﻿#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ESF.SSO.Presenter.Admin.BasicReference;
using ESF.Web.Pages;
using ESF.General.Entity;
using ESF.Web;
using ESF.General;
using ESF.SSO.Web.Tools.Modules;
using ESF.SSO.Core.Entities;
using ESF.SSO.Presenter.Admin;
using ESF.SSO.Core.Entities.BasicReferences;

#endregion


public partial class BasicReference_EditBasicReference : BaseEditPage<EditBasicReferencePresenter, IEditBasicReferenceViewer, LocatedBasicReference>, IEditBasicReferenceViewer
{
	#region Carga Inicial
	
	protected void Page_Load(object sender, EventArgs e)
	{
		_Presenter = new EditBasicReferencePresenter (this);
	
		if (!IsPostBack)
		{
			BasicReferenceTypeID = TextHelper.GetInt (Request.QueryString["BasicReferenceTypeID"]);
			
			_Presenter.Load ();

			btnGoBack.Attributes["onclick"] = JS.GenerateGoToFinal(string.Format("BrowseBasicReferences.aspx?BasicReferenceTypeID={0}", BasicReferenceTypeID));
		}
	}
	
	#endregion


	#region Miembros de IBrowseBasicReferenceViewer

	public string frmTitle
	{
		set
		{
			Title = value;
			lblTitle.Text = value;
		}
	}
	
	
	public int BasicReferenceTypeID
	{
		get
		{
			return Convert.ToInt32 (ViewState ["BasicReferenceTypeID"]);
		}
		set
		{
			ViewState ["BasicReferenceTypeID"] = value;
		}
	}


	public string Code
	{
		get
		{
			return txtCode.Text;
		}
		set
		{
			txtCode.Text = value;
		}
	}

	public string Name
	{
		get
		{
			return txtName.Text;
		}
		set
		{
			txtName.Text = value;
		}
	}
	
	
	public string Description
	{
		get
		{
			return txtDescription.Text;
		}
		set
		{
			txtDescription.Text = value;
		}
	}
	
	
	public bool IsEnabled
	{
		get
		{
			return chkIsEnabled.Checked;
		}
		set
		{
			chkIsEnabled.Checked = value;
		}
	}
	
	
	public string Extra_I
	{
		get
		{
			return txtExtra_I.Text;
		}
		set
		{
			txtExtra_I.Text = value;
		}
	}
	
	
	public string Extra_II
	{
		get
		{
			return txtExtra_II.Text;
		}
		set
		{
			txtExtra_II.Text = value;
		}
	}
	
	
	public string Extra_III
	{
		get
		{
			return txtExtra_III.Text;
		}
		set
		{
			txtExtra_III.Text = value;
		}
	}


	#region Tree Parent

	public List<ESF.General.Entity.BasicReferenceType> TreeBasicReferenceTypeList 
	{
		set
		{
			ListLoader.LoadList (ddlTreeBasicReferenceType, value);
		}
	}


	public ESF.General.Entity.BasicReferenceType TreeBasicReferenceTypeSelected 
	{ 
		get
		{
			return ListLoader.GetSelectedBasicReferenceType(ddlTreeBasicReferenceType);
		}
	}


	public List<ESF.General.Entity.BasicReference> ParentTreeBasicReferenceList 
	{ 
		set
		{
			ListLoader.LoadList(ddlParentTreeBasicReference, value);
		} 
	}


	public ESF.General.Entity.BasicReference ParentTreeBasicReferenceSelected 
	{
		get
		{
			return ListLoader.GetSelectedBasicReference (ddlParentTreeBasicReference);
		}
		set
		{
			ListLoader.Select (ddlParentTreeBasicReference, value);
		}
	}

	#endregion
	
	
	#region Auditoria
	
	public string UserCreationAlias
	{
		set
		{
			uscAuditoryData.UserCreationAlias = value;
		}
		get
		{
			return AuthenticationModule.SignedInUserAlias;
		}
	}
	
	
	public string UserLastUpdateAlias
	{
		set
		{
			uscAuditoryData.UserLastUpdateAlias = value;
		}
	}


	public DateTime? CreationDateTime
	{
		set
		{
			uscAuditoryData.CreationDateTime = value;
		}
	}
	
	
	public DateTime? LastUpdateDateTime
	{
		set
		{
			uscAuditoryData.LastUpdateDateTime = value;
		}
	}
	
	#endregion
	
	#endregion


	#region IEditLocationViewer Members

	public Location Location
	{
		get
		{
			return uscEditLocation.Location;
		}
		set
		{
			uscEditLocation.Location = value;
		}
	}
	
	#endregion
	
	
	#region Metodos de Autocompletado

	[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
	public static string[] QueryCountriesByName (string prefixText, int count)
	{
		return DataHelper.ConvertToStringArray (GeneralAdmin.QueryBasicReferenceList(BasicReferenceTypes.Country, prefixText, count));
	}


	[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
	public static string[] QueryCitiesByName(string prefixText, int count)
	{
		return DataHelper.ConvertToStringArray(GeneralAdmin.QueryBasicReferenceList(BasicReferenceTypes.City, prefixText, count));
	}
	
	#endregion


	#region Dropdownlist Events

	protected void ddlTreeBasicReferenceType_SelectedIndexChanged(object sender, EventArgs e)
	{
		_Presenter.LoadListParentTreeBasicReference ();
	}

	#endregion
	

	#region Button Events

	protected void btnAssociateParentBasicReference_Click(object sender, EventArgs e)
	{
		_Presenter.AssociateTreeParent ();
	}


	protected void btnDESAssociateParentBasicReference_Click(object sender, EventArgs e)
	{
		_Presenter.DESAssociateTreeParent();
	}

	#endregion
}
